<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body style="background-color:#FFF; background-image:url(Hinh/hinh.gif);">
	<style>
		#div1 {-moz-border-radius: 5px; -webkit-border-radius: 5px; border: 1px solid #CCCCCC;
		padding: 10px; background:#af012; width:700px; left:191px; background-color:#CFC; margin:20px}
    </style>

 <div align="center">
	<?php
	
	if (!isset($_SESSION))session_start();
		function hienthi($gh)
  		{
	 		
        	echo "<table id='div1' border='1' >";
			echo "<tr><td>STT</td><td>Mã sản phẩm</td><td>Tên sản phẩm</td><td>Giá</td><td>Số lượng</td><td>Thành tiền</td></tr>";
    	
			$i=0; $tong=0;
			foreach($gh as $m =>$sl)
			{	
				$i++;
				$sql ="select * from sanpham where masp not in (select masp from giamgia) and masp='$m' ";
				$kq = mysql_query($sql);
				if (mysql_num_rows($kq)>0)
				{
					$r =mysql_fetch_array($kq);
					$t = $r["tensp"]; $g = $r['gia'];
					echo "<tr><td>$i</td><td>$m</td>";
					echo "<td>$t</td><td>$g</td>";
					$tt = $g*$sl;  $tong +=$tt;
					echo "<td>$sl</td>";
					echo "<td>$tt</td></tr>";
				}
			  $sql ="select gg.masp, gg.giamoi, sp.tensp, sp.gia from sanpham sp join giamgia gg on sp.masp = gg.masp where gg.masp='$m' ";
				$kq = mysql_query($sql);
				if (mysql_num_rows($kq)>0)
				{
					$r =mysql_fetch_array($kq);
					$t = $r[2]; $g = $r[1];
					echo "<tr><td>$i</td><td>$m</td>";
					echo "<td>$t</td><td>$g</td>";
					$tt = $g*$sl;  $tong +=$tt;
					echo "<td>$sl</td>";
					echo "<td>$tt</td></tr>";
				}
		}
		echo "<tr><td colspan=10>Tổng số tiền</td><td>$tong</td></tr>";
		echo "</table>";
	 }
		
		if (!isset($_SESSION['username']))
		{ 
			echo "Khách hàng cần đăng nhập trước khi mua hàng!"; echo "<b><a href=include/info/dangnhap.php>Đăng nhập</a></b>";
			exit;
		}
	
		if (!isset($_SESSION["giohang"]))
		{
			echo "Khách hàng cần chọn sản phẩm để mua hàng! "; echo "&nbsp; <a href=khachhang.php?action=product>Xem sản phẩm</a>"; exit;
		}
		
		$giohang = $_SESSION['giohang'];
		
		if (count($giohang)==0)
		{
			echo "Khách hàng cần chọn sản phẩm để mua hàng! "; echo "&nbsp; <a href=khachhang.php?action=product>Xem sản phẩm</a>"; exit;
		}
	
		$username = $_SESSION["username"];
		include_once("connect.php");
		
		$sql = "select * from khachhang where username ='$username' ";
		$kq = mysql_query($sql);
		if (mysql_num_rows($kq)==0)
			exit;
			
		$r = mysql_fetch_array($kq);
		$tkh = $r['ten'];
		$ho = $r['ho'];
		$dc = $r["diachi"];
		$dt = $r['sdt'];
	?>
 <?php
//MX Widgets3 include
require_once('include/wdg/WDG.php');
?>
<script src="include/common/js/base.js" type="text/javascript"></script>
<script src="include/common/js/utility.js" type="text/javascript"></script>
<script type="text/javascript" src="include/wdg/classes/MXWidgets.js"></script>
<script type="text/javascript" src="include/wdg/classes/MXWidgets.js.php"></script>
<script type="text/javascript" src="include/wdg/classes/Calendar.js"></script>
<script type="text/javascript" src="include/wdg/classes/SmartDate.js"></script>
<script type="text/javascript" src="include/wdg/calendar/calendar_stripped.js"></script>
<script type="text/javascript" src="include/wdg/calendar/calendar-setup_stripped.js"></script>
<script src="include/resources/calendar.js"></script>

<link href="include/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />

    
    <div>
        <table id="div1"  align='center' >
            <tr><td conspan=2 align="center">THÔNG TIN KHÁCH HÀNG </td></tr>
            <tr><td>Username</td><td align="left"><?php echo $username; ?></td></tr>
            <tr><td>Họ tên</td><td><?php echo $tkh." ". $ho; ?></td></tr>
            <tr><td>Điện thoại</td><td><?php echo $dt; ?></td></tr>
            <tr><td>Địa chỉ</td><td><?php echo $dc; ?></td></tr>
        </table>
    </div>

    <div>
        <form action=xulydonhang.php method=post>
            <table id="div1"  align='center'>
                <tr><td colspan=2 align="center"> THÔNG TIN NGƯỜI NHẬN</td></tr>
                <tr><td>Tên người nhận</td><td><input type="text" name="tennguoinhan"></td></tr>
                <tr><td>Địa chỉ người nhận</td><td><input type="text" name="diachinguoinhan"></td></tr>
                <tr><td>Điện thoại người nhận</td><td><input type="text" name="dienthoainguoinhan"></td></tr>
                <tr><td>Ngày nhận(YY/MM/DD)</td><td><input name="ngaynhan" id="ngaynhan" value="" size = "20" wdg:subtype="Calendar" wdg:mask="<?php echo $KT_screen_date_format; ?>" wdg:type="widget" wdg:mondayfirst="true" wdg:singleclick="false" wdg:restricttomask="no" wdg:readonly="true"></td></tr>
                <tr><br/><td align="right"><input type="submit" value="Đồng ý"></td><td align="left"><a href="khachhang.php?action=home"><input type="button" value="Hủy"></a></td></tr>
            </table>
        </form>
    </div>

    <div id="div1"  align='center'>
        THÔNG TIN ĐƠN HÀNG
        <?php 
        hienthi($giohang);
        ?>
    </div>

 </div>
</body>
</html>
